package com.oneandseven.dajia.base.generator;

import com.oneandseven.dajia.base.generator.snowflake.SnowFlake;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.util.UUID;

@Slf4j
public class CustomIDGenerator implements IdentifierGenerator {

    @Override
    public String generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) {
        try {
            return String.valueOf(SnowFlake.getInstance().nextId());
        } catch (Exception e) {
            log.info("CustomIDGenerator creatId error", e);
        }
        return UUID.randomUUID().toString();
    }
}
